package util;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import java.util.Timer;
import java.util.TimerTask;

@WebListener
public class SessionAttribuListener implements HttpSessionAttributeListener {
    @Override
    public void attributeAdded(final HttpSessionBindingEvent event) {
        String name = event.getName();

        if(name.equals("shortMsg")){
            java.util.Timer timer = new Timer();
             timer.schedule(new TimerTask() {
                 @Override
                 public void run() {
                     HttpSession session = event.getSession();
                     session.removeAttribute("shorMsg");
                 }
             },60*1000);
        }
    }
}
